//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.itheima.service.impl;

import com.itheima.mapper.CategoryMapper;
import com.itheima.pojo.Category;
import com.itheima.service.CategoryService;
import com.itheima.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    public CategoryServiceImpl() {
    }

    public void add(Category category) {
        Map<String, Object> map = (Map)ThreadLocalUtil.get();
        Integer userId = (Integer)map.get("id");
        category.setCreateUser(userId);
        this.categoryMapper.add(category);
    }

    public List<Category> list() {
        Map<String, Object> map = (Map)ThreadLocalUtil.get();
        Integer userId = (Integer)map.get("id");
        return this.categoryMapper.list(userId);
    }

    public Category finById(Integer id) {
        Category c = this.categoryMapper.findById(id);
        return c;
    }

    public void update(Category category) {
        this.categoryMapper.update(category);
    }


    public void deleteById(Integer id) {
        this.categoryMapper.deleteById(id);
    }
}
